home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / A-B / Alpha.5.05.cpt / shell.tcl < prev    next >
Text File  |  1992-09-06  |  1KB  |  64 lines

  1.  
  2. proc initShell {} {
  3.     insertText "Welcome to Alpha's Tcl shell."
  4.     shellPrompt [lindex [winNames] 0]
  5. }
  6.  
  7. # Output the prompt. We want the window name because some of the commands
  8. # we evaluate (such as 'edit') open a new window, and we want the insertion
  9. # to be done in the shell window.
  10. proc shellPrompt {winName} {
  11.     regexp "(\[^:\]*):$" [pwd] crDum crDir
  12.     insertText -w $winName "\r" $crDir "> "
  13. }
  14.  
  15.  
  16. # Called at all carriage returns.
  17. proc carriageReturn {} {
  18.     global mode
  19.     set indentString ""
  20.     deleteText [getPos] [selEnd]
  21.     if {[getVar indentOnCR]} {
  22.         set pos [getPos]
  23.         set text [getText [lineStart $pos] $pos]
  24.         for {set i 0; set len [string length $text]} {$i <= $len} {incr i} {
  25.             set c [string index $text $i]
  26.             if {($c != "\t") && ($c != "\ ")} {
  27.                 set indentString [string range $text 0 [expr $i-1]]
  28.                 break
  29.             }
  30.         }
  31.     }
  32.     insertText "\r" $indentString
  33. }
  34.  
  35.  
  36. proc tclCarriageReturn {} {
  37.     global mode
  38.     uplevel #0 {
  39.         set oldFor [getVar forward]
  40.         set oldReg [getVar regExpr]
  41.         set oldMatch [getVar matchWords]
  42.         set fileName [lindex [winNames] 0]
  43.         setVar forward 0
  44.         setVar regExpr 0
  45.         setVar matchWords 0
  46.         goto [maxPos]
  47.         set crText [getText [expr "[lindex [search ">" [maxPos]] 0]+2"] [maxPos]]
  48.         catch $crText crRes
  49.         if {[string length $crRes]} {
  50.             insertText -w $fileName "\r" $crRes
  51.         } 
  52.         shellPrompt $fileName
  53.         setVar forward $oldFor
  54.         setVar regExpr $oldReg
  55.         setVar matchWords $oldMatch
  56.     }
  57. }
  58. bind '\r' carriageReturn
  59. bind '\r' tclCarriageReturn "Csh"
  60.  
  61. #    tclCarriageReturn
  62.  
  63.  
  64.